package offer;

/**
 * 描述:剑指 Offer 53 - I. 在排序数组中查找数字 I
 *
 * @author Madison You
 * @created 23:12
 */
public class Easy_53_Search {
    public static void main(String[] args) {
        new Easy_53_Search().search(new int[]{5, 7, 7, 8, 8, 8, 8, 10}, 8);
    }

    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int count = 0;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] >= target) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        while (left < nums.length && nums[left++] == target) {
            count++;
        }
        return count;
    }

}
